import {
  PrimaryGeneratedColumn,
  Column,
  BeforeInsert,
  BeforeUpdate,
} from 'typeorm';

/**
 * 实体基类，包含所有实体共有的字段和方法
 */
export abstract class BaseEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ select: false })
  createBy: number;

  @Column({ select: false })
  createTime: Date;

  @Column({ select: false })
  updateBy: number;

  @Column({ select: false })
  updateTime: Date;

  @BeforeInsert()
  BeforeInsert() {
    this.createTime = new Date();
    this.updateTime = this.createTime;
  }

  @BeforeUpdate()
  BeforeUpdate() {
    this.updateTime = new Date();
  }
}
